package com.cskaoyan.controller;

import com.cskaoyan.bean.CskaoyanmallStorage;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.StorageListVo;
import com.cskaoyan.service.AdminStorageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Fantasylkh
 */
@RestController
public class AdminStorageController {

    @Autowired
    AdminStorageService storageService;


    @RequiresPermissions("admin:storage:list")
    @RequestMapping("/admin/storage/list")
    public BaseRespVo storageList(int page, int limit, String key, String name, String sort, String order) {
        StorageListVo storageListVo = storageService.storageList(page, limit, key, name, sort, order);
        return BaseRespVo.success(storageListVo);
    }

//    @RequestMapping("/admin/storage/create")
//    public BaseRespVo storageCreate() {
//        return null;
//    }

    @RequiresPermissions("admin:storage:update")
    @RequestMapping("admin/storage/update")
    public BaseRespVo storageUpdate(@RequestBody CskaoyanmallStorage storage) {
        CskaoyanmallStorage storageUpdate = storageService.storageUpdate(storage);
        if (storageUpdate == null) {
            return BaseRespVo.fail(-1);
        }
        return BaseRespVo.success(storageUpdate);
    }

    @RequiresPermissions("admin:storage:delete")
    @RequestMapping("/admin/storage/delete")
    public BaseRespVo storageDelete(@RequestBody CskaoyanmallStorage storage) {
        Integer effect = storageService.storageDelete(storage);
        if (effect != 0 ) {
            return BaseRespVo.success();
        }
        return BaseRespVo.fail(-1);
    }

}
